#!/usr/bin/perl -T
# spell.pl
use warnings;
# lack of use strict
 

use CGI qw(:standard *table *ul);
use Lingua::EN::Syllable;
use Lingua::EN::Nickname;
use Lingua::EN::Fathom;
use Lingua::Ispell qw(spellcheck);

print header, start_html(-bgcolor => white,
                         -title => "Reporting");
if (!param(report)) {
   print start_table({bgcolor => 'lightblue', cellspacing => 0, 
                      cellpadding => 5}), start_form,
   Tr(td(["Name" , textfield('name')])), "\n", 
   Tr(td(["Report" , textarea('report')])), "\n", 
   Tr(td({colspan => 2, align => 'center'}, submit())), end_form, end_table;
} else {
   my $text = new Lingua::EN::Fathom; 
   my $report = param('report');
   $text->analyse_block($report);
   my $numSyll = syllable($report);
   $report =~ s/\n//g;   # needed by spellcheck
$Lingua::Ispell::path = '/usr/bin/ispell';
   my @checks = spellcheck($report);
   my %errors;
   for (@checks) {
      $errors{$_->{term}} = $_->{misses} if ( $_->{type} = 'miss');
   }
   print h1("Received report by ", nickroot(param(name)), ":"),
   p(em(param(report))),
   p("Which has received the following ratings"),
   start_ul, li("Fog = ", $text->fog ),
   li("Kincaid = ", $text->kincaid),
   li("Flesch = ", $text->flesch),
   end_ul,
   p("And had the following misspellings "), start_ul;
   for (keys %errors) {
      print li($_, " Suggestions :", join(" ", @{$errors{$_}}));
   }
   print end_ul, p("And you will be paid ", $numSyll*0.25, "\$ for 
                    $numSyll syllables ");
}
print end_html;
